package com.jinxiangyang.controller;


import com.jinxiangyang.annotation.OperateLog;
import com.jinxiangyang.domain.Chapter;
import com.jinxiangyang.domain.vo.ChapterVo;
import com.jinxiangyang.service.ChapterService;
import com.jinxiangyang.utils.enums.BusinessType;
import com.jinxiangyang.utils.enums.OperatorType;
import com.jinxiangyang.utils.result.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author jinxiangyang
 * @since 2023-08-12
 */
@RestController
@RequestMapping("/chapter")
@Api(tags="章节控制器")
public class ChapterController {

    @Autowired
    private ChapterService chapterService;


    @GetMapping("{cid}")
    @OperateLog(title = "章节管理模块",businessType = BusinessType.OTHER,operatorType = OperatorType.TEACHER)
    public AjaxResult getChapterByCid(@PathVariable Integer cid){
        return AjaxResult.success();
    }

    //大纲列表

    @GetMapping("/getList/{courseId}")
    @ApiOperation("课程大纲")
    @OperateLog(title = "章节管理模块",businessType = BusinessType.OTHER,operatorType = OperatorType.TEACHER)
    public AjaxResult getList(@PathVariable Long courseId){
       List<ChapterVo> list = chapterService.getTreeList(courseId);
        return AjaxResult.success(list);
    }

    //添加章节
    @PostMapping("/save")
    @ApiOperation("添加课程信息")
    @OperateLog(title = "章节管理模块",businessType = BusinessType.INSERT,operatorType = OperatorType.TEACHER)
    public AjaxResult save(@RequestBody Chapter chapter){
       chapterService.save(chapter);
       return AjaxResult.success();
    }

    @GetMapping("get/{id}")
    @ApiOperation("根据id进行查询")
    @OperateLog(title = "章节管理模块",businessType = BusinessType.OTHER,operatorType = OperatorType.TEACHER)
    public AjaxResult get(@PathVariable Long id){
        Chapter chapter = chapterService.getById(id);
        return AjaxResult.success(chapter);
    }

    @PutMapping("/update")
    @ApiOperation("根据id修改课程")
    @OperateLog(title = "章节管理模块",businessType = BusinessType.INSERT,operatorType = OperatorType.TEACHER)
    public AjaxResult update(@RequestBody Chapter chapter) {
        chapterService.updateById(chapter);
        return AjaxResult.success();
    }

    @DeleteMapping("/remove/{id}")
    @ApiOperation("根据id进行逻辑删除")
    @OperateLog(title = "章节管理模块",businessType = BusinessType.INSERT,operatorType = OperatorType.TEACHER)
    public AjaxResult delete(@PathVariable Long id){
        chapterService.removeById(id);
        return AjaxResult.success();
    }


}

